package com.yin.myproject.netty.chapter05;

import com.yin.myproject.netty.ChildServerHandler;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;

/**
 * @author Eason
 * @create 2017-12-24 18:02
 **/
public class EchoServerChildHandler extends ChildServerHandler {

    public EchoServerChildHandler(ChannelHandler channelAdapter) {
        super(channelAdapter);
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ByteBuf delimter = Unpooled.copiedBuffer("$_".getBytes());
        socketChannel.pipeline().addLast(new DelimiterBasedFrameDecoder(1024,delimter));
        socketChannel.pipeline().addLast(new StringDecoder());
        socketChannel.pipeline().addLast(channelAdapter);
    }
}
